Syntax20m.Scn.Fnt ParcElems Alloc Syntax12i.Scn.Fnt Syntax14m.Scn.Fnt StyleElems Alloc Title Syntax12.Scn.Fnt Title Syntax10.Scn.Fnt Example ExprIcons Alloc ExprStd AllocInteger ExprStd AllocSymbol ExprStd AllocBinaryOp ExprStd AllocFunction ExprLib0 AllocIntegral P G ; < ExprStd AllocPower ExprLib0 AllocRoot ExprLib0 StdConstAlloc infinity ExprLib0 AllocLimit ExprViews AllocPlaceholder ExprLib0 AllocGreek alpha ExprLib0 AllocFunction ExprLib0 AllocBinomial Alpha Delta delta Epsilon epsilon Gamma gamma Kappa kappa Lambda lambda Theta theta Sigma sigma Upsilon upsilon Omega omega ExprMatrices Alloc ExprIcons AllocGraph ExprSlang Alloc Example ExprSlang Alloc Title Title Syntax12m.Scn.Fnt SubTitle Example ExprSlang Alloc Example Example ExprSlang Alloc ExprSlang Alloc ExprSlang Alloc SubTitle Example ExprSlang Alloc Example SubTitle SubTitle SubTitle SubTitle Example TableElems Alloc Syntax12.Scn.Fnt StyleElems Alloc /nolines "lrtb" /noheads "V" /columns "ccl" /table primary button secondary button left focus middle decompose middle left open Example Syntax12.Scn.Fnt StyleElems Alloc /nolines "lrtb" /noheads "V" /columns "ccl" /table primary button secondary button right set subselection right left replace subselection by least recent selection right middle copy-over subselection to focus Title Title Example Example ExprSlang Alloc Title Example ExprSlang Alloc Example ExprSlang Alloc ExprSlang Alloc ExprSlang Alloc Example ExprSlang Alloc ExprSlang Alloc ExprSlang Alloc ExprSlang Alloc ExprSlang Alloc LineElems Alloc Example ExprSlang Alloc ExprSlang Alloc ExprSlang Alloc ExprSlang Alloc Example ExprSlang Alloc Example Example ExprSlang Alloc ExprSlang Alloc Title Title Table ExprSlang Alloc ExprSlang Alloc ExprSlang Alloc ExprSlang Alloc ExprSlang Alloc ExprSlang Alloc ExprSlang Alloc ExprSlang Alloc ExprSlang Alloc ExprSlang Alloc ExprSlang Alloc ExprSlang Alloc ExprSlang Alloc ExprSlang Alloc ExprSlang Alloc ExprSlang Alloc ExprSlang Alloc ExprSlang Alloc ExprSlang Alloc ExprSlang Alloc ExprSlang Alloc ExprSlang Alloc ExprSlang Alloc ExprSlang Alloc Table ExprSlang Alloc ExprSlang Alloc ExprSlang Alloc ExprSlang Alloc ExprSlang Alloc ExprSlang Alloc ExprSlang Alloc ExprSlang Alloc ExprSlang Alloc ExprSlang Alloc ExprSlang Alloc ExprSlang Alloc ExprSlang Alloc ExprSlang Alloc ExprSlang Alloc ExprSlang Alloc ExprSlang Alloc ExprSlang Alloc ExprSlang Alloc ExprSlang Alloc ExprSlang Alloc ExprSlang Alloc ExprSlang Alloc ExprSlang Alloc ExprSlang Alloc ExprSlang Alloc ExprSlang Alloc ExprSlang Alloc ExprSlang Alloc ExprSlang Alloc ExprSlang Alloc ExprSlang Alloc ExprSlang Alloc ExprSlang Alloc ExprSlang Alloc ExprSlang Alloc ExprSlang Alloc ExprSlang Alloc ExprSlang Alloc ExprSlang Alloc ExprSlang Alloc ExprSlang Alloc ExprSlang Alloc ExprSlang Alloc ExprSlang Alloc ExprSlang Alloc ExprSlang Alloc ExprSlang Alloc Table Title Table ExprSlang Alloc ExprSlang Alloc ExprSlang Alloc Table Title Example ExprSlang Alloc Example ExprSlang Alloc Example ExprSlang Alloc Example ExprSlang Alloc ExprSlang Alloc Example ExprSlang Alloc Example ExprSlang Alloc Example ExprSlang Alloc Example ExprSlang Alloc Example ExprSlang Alloc Example ExprSlang Alloc ExprSlang Alloc ExpressionIcons - User's Guide Wolfgang Weck Institute for Scientific Computing ETH Z Weck@inf.ethz.ch Introduction ExpressionIcons are an extension of the Oberon text system which allows for representation and editing of mathematical expressions while floating within text documents. Expressions can be transformed seamlessly between textual and iconized representation. In particular, an expression can be represented in a mixed way. Since conversions between text and icons are very simple, the text editor can be used as the basic tool for editing while the icons provide two dimensional graphical visualization. The effort spent in acquainting is reduced dramatically, given that the user is familiar with the text editor. Further, selections of subexpressions within ExpressionIcons are supported. These integrate the copy_over facility of the text framework, allowing for graphic oriented editing as an alternative. The underlying internal data structure for expressions forms an abstract data type. It is a powerful basis for any computation command. Expressions represented as ExpressionIcons can easily be used to interface such commands, i.e. to represent input as well as output. The distinction between text generated from such commands or by the user becomes obsolete, so does the separation of input and output of commands. Usually, commands can operate on expressions represented in any mixed form (text and icons) as well as on subexpressions selected within an icon. There is no need to convert text to an icon before activating a command. In the case of huge formulae elision is used to reduce the space needed. Entire subexpressions will become hidden, showing three dots instead. The user still can see the overall structure of the expression without loosing the overview. To zoom into subexpressions partial convertion to text is used to retrieve a new icon representing only the subexpression in question but displaying more details. This document gives an introduction to the usage of ExpressionIcons. It is assumed that the reader is familiar with text editing in Oberon. It is explained how expressions can be generated, edited, and used as input for commands. This document tries to be readable in both a static form (e.g. printed on paper) as well as in an interactive form on the computer screen. In case of the latter, the reader is encouraged to experiment with the expressions given as examples. Elision It is quite often impossible to display an expression generated by Computer Algebra in its full size and to every detail. On one hand, screen size (or paper size) limits the space availlable; on the other hand details would be shown too small to be readable. Still, the user's needs may vary between getting the overview and looking at a specific detail. These two extremes - and anything between - should be supported in some way. ExpressionIcons use a top down approach: Of a large expression the overall structure is visible, details are collapsed and displayed as an elision (three dots - occasionally presenting a number giving the size of the folded part). This allows to see immediately, that something is e.g. a sum of integrals, or an even integer with 134 digits: To get information about a specific detail of an expression like this, one should use one of the methods described below, to zoom in. (E.g. to see all the digits of the integer number, you may open the icon, by performing an middle-left-interclick with the mouse on the icon.) The level of elision, i.e. the degree of detail used for representation, can be set individually for each ExpressionIcon. Placeholders Placeholders are a special kind of expressions. They do not have a value assigned and are all equivalent with each other. They are displayed as question_marks. Placeholders do not have a textual representation. Therefore, they can neither be typed in nor can an icon representing just a Placeholder be converted to text. New Placeholders can be generated with the command ExprTools.NewPlaceholder which inserts an icon representing a Placeholder at the current insertion point. Placeholders are used as special marks with certain operations. Most important is their usage with copy_over (see below) to resemble Overlays. Mouse Commands on ExpressionIcons In the first place, ExpressionIcons act as parts of a text. The mouse commands of the text editor can be used to copy, delete, or change attributes of ExpressionIcons. Some mouse commands are handled specially by ExpressionIcons. These are described in the following. Decomposition Clicking the middle button of the mouse on an ExpressionIcon causes the icon to decompose itself into text on the highest structural level of the expression represented. An ExpressionIcon representing e.g. a product of powers will be rewritten as a sequence of ExpressionIcons representing the individual factors with asterisk characters between them: clicking the middle mouse button leads to This operation can be used to decompose a specific part of an expression into text allowing for editing. To convert a text back to an ExpressionIcon select the text in question and execute the ExprTools.Collapse command. To convert an Expression entirely to text, not only the first level, use one of the commands ExprTools.ConvertToText or ExprTools.Write (see below). Opening Clicking the middle mouse button on an ExpressionIcon and interclicking the left button before releasing the mouse buttons opens the icon: The textual decomposition as described in the previous section will be shown in a separate viewer which is opened. The original ExpressionIcon remains unchanged. The text displayed can be edited, using the normal text editing operations of the Oberon System. The command Icons.Update in the menu bar of the viewer can be used to update the icon opened in the first place. It is not necessary to convert the text in the viewer itself into an ExpressionIcon before. This facility can be used to get an extra scratch pad for expression editing. It allows to decompose parts of the expression without corrupting the original document. Further, it allows to cancel an editing operation, simply by not updating the icon. Another application is to get a quick insight into an expression with elisions. click middle mouse button, interclick left mouse button If an ExpressionIcon that holds a subselection (see below) is opened, only the selected subexpression is shown in the viewer. Also, an update will affect only this subexpression. This is especially helpful when dealing with large expressions. Focusing The operations described in the following sections use selections within an ExpressionIcon, so called subselections. Before any subselection can be made, the corresponding icon has to be focused by clicking the left mouse button on it. After releasing the mouse button, a dotted frame is displayed surrounding the icon. After this, any of the following operations can be executed. Making Subselections Most of the commands operating on expressions can operate either on text, a text selection, or a subselection. A subselection is the selection of a subexpression within an ExpressionIcon. Operations on subselections will change the value of the selected subexpression only. To set a subselection, first focus the icon holding the expression in question by clicking the left mouse button on it. Afterwards you can set a selection within the framed icon, by pressing the right mouse button and holding it while moving the mouse around. As for text, the selected subexpression is displayed in an inverted mode. Only entire substructures of an expression can be selected. E.g. from a sum with several terms one can either select one of the individual terms or the entire sum, but not a partial sum. Selected subexpressions might be used as input to a command or with the copy_over facility of Oberon's text system. A subselection might also be used before opening an icon to display a specific subexpression only. Copy_Over Besides for copying entire ExpressionIcons as atoms, the copy_over facility of Oberon's text system can also be used to copy subexpressions. This is achieved by the fact, that any expression can be seen as text - e.g. as one single icon, representing this expression. Hence, a selected subexpression also has a textual appearance. On the other hand, if any selected piece of text can be interpreted as a valid expression, it can be converted and stored as a subexpression. From these considerations follows, that all combinations of copying between text and subexpressions are possible. Unlike the text system, where the insertion point (caret) and selections are handled separately, subselections within ExpressionIcons serve as both simultaneously. This is due to the underlying expression model, which allows as its only operation the replacement of entire subexpressions by complete and valid expressions. Focusing an ExpressionIcon (see above) makes it the target for copy_over operations. If several ExpressionIcons are focussed at the same time, the target is the least recent focused one of those. If this target holds a subselection, copying a piece of text or another subexpression with a right_middle_interclick will replace the selected subexpression. Interclicking the left mouse button while selecting within a focussed icon will lead to the replacement with the finally selected subexpression by the least recent previous selection - no matter whether the latter is a text selection or a subselection. Important note: It is not possible within one viewer to have two icons focused at the same time nor to have a focused icon and a text selection. Use the System.Copy-command to generate a second viewer before using copy_over within a single document. Placeholders have a special role when used in the source to copy_over into a subexpression: As described above, if the target is a subselection, the selected subexpression will be replaced by the source. If the source, i.e. the replacement for the subselection, contains Placeholders, all of them are replaced by the selected target expression. If the source does not contain any Placeholder, the old expression is discarded. The application of this is mainly to create overlays in contrast to templates. For a description of these concepts see the section How to produce an ExpressionIcon bellow. Summary of Mouse Commands On unfocused ExpressionIcons the usual mouse commands of the hosting text editor can be used. Additionally the following operations as described above are available: On ExpressionIcons being focused before and surrounded by a dotted frame the commands for subselections can be used: How to Convert ExpressionIcons to Text There exist four general ways to convert an expression represented by an ExpressionIcon into text. An icon can either be decomposed with a click of the middle button or opened it with an middle-left-interclick. Both operations will produce a text where larger subexpressions are still represented as icons. Decomposition replaces the original icon by that text but opening openes an additional viewer presenting a text editor. An expression can entirely be converted to text either by recursive application of decomposition or by one of the commands ExprTools.ConvertToText and ExprTools.Write. Both act on the least recent selection. Whereas ExprTools.ConvertToText replaces the icon by the text, ExprTools.Write will leave the icon unchanged and produce a new text stretch at the position of the current focus. If the current focus is an subselection in an icon, it will act like copy_over. A text converted from an icon may contain some unnecessary parentheses. To get rid of a pair of extra parentheses in a text, one can select the opening parenthesis and execute the command ExprTools.RemovePar. But be aware, that this operation might change the meaning of your expression! The Text Representation of Expressions In the plain text form expressions are represented as a linear sequence of characters. ExpressionIcons within such a sequence represent subexpression. For the rest, the meaning of the text is defined by a special extensible language. In the core system the syntax of this language is fixed as follows: equation := expr [ "=" expr]. expSeq := equation {"," equation}. index := "[" expSeq "]". expr := ["-"] term {addop term}. term := factor {mulop factor}. factor := {atom "^"} atom. atom := ("(" equation ")" | function | collection | symbol | integer | subExpression) [index]. function := name "(" [expSeq] ")". collection := "{" [expSeq] "}". symbol := name. name := letter {letter | digit}. integer := digit {digit}. The default parser, used to form ExpressionIcons or to read input to commands, tries to read its input as an equation. The set of expressions is extended by a postprocessor that transforms specific expressions into others. In most cases, special named functions are used for that purpose. A set of standard extensions is defined in the ExprLib0 module, e.g. Integral expressions. They have two representations, a two dimensional one and one as a function: The exact binding of function names and expressions needs to be defined in the corresponding extension. For the definition of the expressions defined in the ExprLib0 module see the corresponding section below. How to produce an ExpressionIcon The equivalent of entering an expression into a classical expression editor is to produce an ExpressionIcon. There are two general ways to do so but any combination of these is possible and it is left to the user and his or her creativity to find the way suiting best both user's skill and situation's demands. One simple way to enter an expression is to type it on the keyboard. The resulting text can be used as input to any command. Simply converting the text into an icon can be considered as a special case of this and is achieved through the command ExprTools.Collapse ^. However, to be able to type in a complicated expression, the user is required to get some knowledge about the textual representation of the parts to be used. To type in the following expression for instance requires knowledge about the representation of limits and integrals as functions. The text to type for the example above would be limit(int(x^(1 / n), x, 0, const(infinity)), x, 0, 1). If the textual representation of some or all expressions involved is unknown, a mouse_driven method based on templates or on overlays might be used. Both cases employ the copy_over facility and a palette of prepared patterns (like the one stored in ExprPalette.Text). Since thus palettes can be realized as texts, they exhibit the same flexibility as tool texts in the Oberon system. These approaches are easy to use and do not require any extra knowledge besides usage of the copy_over facility. The difference between templates and overlays is that in case of the former a pattern is simply copied unchanged, whereas overlays modify an already existing expression. As an example for the latter consider an expression like that should be transformed into . This can be achieved by copying the overlay pattern onto the fraction. As an example for the usage of templates it is shown below how to compose a new formula from the following patterns: -> -> -> -> Note, that when opening a copied template for editing the comparison of the subexpressions in the opened text and the template itself will guide the user to identify the order of the function parameter. E.g., when opening integral template from the example above one will see int(f(x), x, a, b) and immediately recognize that the order of the parameters are integrand, integration variable, lower bound, and upper bound. Obviously it is a good idea to use such different symbols in a template. For that reason the following is considered to be a poorly designed template: As mentioned before, any mixture of these techniques can be applied. E.g. one might copy the limit template, because the textual representation is currently unknown, open the new icon, delete the argument and replace it by a typed expression representing the integral... Extensions and Automatic Substitutions The set of representable expressions is extensible. New modules might be provided implementing additional expression types. Most such modules will offer two representations for the expression types they define: One customized to represent the expression in a two dimensional way and one in the standard language, as understood by the standard parser. Most of the time special function names will be defined and all subexpressions will be given as a parameter to this function. Normally such a module will install an automatic substitution mechanism upon loading. Thus, whenever the standard parser is used to read input, the extended expression types are used automatically. Also, when converted to text, the special expressions will be converted back to their representation in the standard language gradually. Although there are commands to do these things manually, the automatic transformations will suit most of the user's purposes. Two extension modules being part of the standard system are described in the following. The Lib0 Extensions The following list shows for each of the expressions implemented in module ExprLib0 the templates and the corresponding representation as a function in the standard language: abs(x) norm(x) ceiling(x) floor(x) factorial(x) gamma(x) binomial(x, y) int( , x) int( , x, a, b) limit( , x, 0, 0) limit( , x, 0, 1) limit( , x, 0, -1) const(pi) const(e) const(infinity) The function greek with one argument is interpreted as a symbol to be represented as a greek letter: greek(Alpha) greek(alpha) greek(Beta) greek(beta) greek(Chi) greek(chi) greek(Delta) greek(delta) greek(Epsilon) greek(epsilon) greek(Gamma) greek(gamma) greek(Eta) greek(eta) greek(Iota) greek(iota) greek(Phi) greek(phi) greek(Kappa) greek(kappa) greek(Lambda) greek(lambda) greek(Mu) greek(mu) greek(Nu) greek(nu) greek(O) greek(o) greek(Pi) greek(pi) greek(Theta) greek(theta) greek(Rho) greek(rho) greek(Sigma) greek(sigma) greek(Tau) greek(tau) greek(Upsilon) greek(upsilon) greek(Omega) greek(omega) greek(Xi) greek(xi) greek(Psi) greek(psi) greek(Zeta) greek(zeta) All these extensions are made available for automatic usage by the standard parser upon module loading. The module is loaded as soon as a document is opened, that contains at least one of the expressions implemented in ExprLib0, e.g. the ExprPalette.Text or this document. It can also be loaded explicitly by executing one of the commands listed below. These commands install resp. remove the automatic conversion by the standard parser for specific expression types. Note however, that upon loading the module all extensions defined are installed simultaneously, no matter which command was executed. Also note, that these commands will only change the behavior of the standard parser but not affect expressions already in existence. ExprLib0.InstallConsts ExprLib0.RemoveConsts ExprLib0.InstallBinomials ExprLib0.RemoveBinomials ExprLib0.InstallGreeks ExprLib0.RemoveGreeks ExprLib0.InstallFunctions ExprLib0.RemoveFunctions ExprLib0.InstallRoots ExprLib0.RemoveRoots ExprLib0.InstallIntegrals ExprLib0.RemoveIntegrals ExprLib0.InstallLimits ExprLib0.RemoveLimits The Matrix Extension The module ExprMatrices implements a further expression, a construct to represent matrices. Vectors might be represented as matrices of height 1 resp. width 1. Examples: matrix(1, 4, a, b, c, d) matrix(4, 1, a, b, c, d) matrix(2, 2, a, b, c, d) Like the extensions defined in module ExprLib0 the automatic conversion for the matrix extension is installed either by opening a document containing a matrix or by executing a command from the module: ExprMatrices.Install ExprMatrices.Remove The ExprTools commands The module ExprTools serves as a user interface and offers a collection of commands. These are described in this section: ExprTools.Iconize n ^ n being an (optional) positive integer; focus (caret) needs to be set A new ExpressionIcon representing the least recent selected expression is generated and inserted at the current focus position (caret). The selection might be a text stretch as well as a subselection in an already existing ExpressionIcon. The number n gives the level of representation before elision is used for the new icon; if omited a default value is used. ExprTools.Collapse n ^ n being an (optional) positive integer The least recent subselection is parsed, interpreted as an expression, and replaced by an ExpressionIcon. If the least recent selection is a subselection within an icon, the automatic substitutions are applied to the corresponding subexpression without further changes. The number n gives the level of representation for the new icon; if omited a default value is used. This command might also be used to set the level of representation to a specific value and to apply the automatic substitutions to an already existing ExpressionIcon. If the command is applied to a text stretch with several expressions, the operation is applied to each of them individually. ExprTools.Write ^ focus (caret) needs to be set Generates are purely textual representation of the selected expression and copies it to the current focus position. The selection is not affected. ExprTools.ConvertToText ^ Replaces the current selected expression by its textual representation. Has no effect on subselections. If the command is applied to a text stretch with several ExpressionIcons, the operation is applied to each of them individually. ExprTools.IncDepth n ^ n being a signed integer The level of representation is incremented for all ExpressionIcons within the least recent selected text stretch according to n. A negative number reduces the amount of visible data whereas a positive number increases it. ExprTools.Substitute e1 => e2 ~ e1 and e2 being expressions All subexpressions being equal to e1 are replaced by e2 in the least recently selected (sub_)expression. Besides others, this command can be used to do common subexpression elimination and to substitute back: ExprTools.Substitute => w ExprTools.Substitute w => s => ExprTools.TestEquation ^ an equation needs to be selected A statement is written to the log text, saying wether the equations holds. Note that no mathematical transformations are applied. In case of commuting operands (e.g. terms in sums) commutation is taken into account. Associativity is not considered. An expression claimed to hold will always hold, whereas the statement that an equation does not hold simply means that the command was not able to find a way to transform both sides to a unique representation by simple means. equation holds equation does not hold equation holds equation does not hold ExprRatCalc.Simplify ^ Simplifies the least recent selected expressions and its subexpression by performing rational computations, as far as possible. ExprRatCalc.Simplify